let App = getApp();

Page({
  data: {

    default_id: null,
    list:[
  ],
  searchValue:""
  },

  onLoad: function(options) {
    // 当前页面参数

  },
   /**
   * 绑定输入值
   */
  getSearchContent: function (e) {
    this.data.searchValue = e.detail.value;
  },
  search(){

      this.getdata(this.data.searchValue);
  },
  getdata(keys){
    var _this = this;
    App._post_form('wxapi/person/list', {keys:keys}, result => {
      _this.setData({list:result.data});
    });
  },

  onShow: function() {
    // 获取收货地址列表

    this.getdata("")
  },

  /**
   * 获取收货地址列表
   */
  getAddressList: function() {
    let _this = this;
    App._get('address/lists', {}, function(result) {
      _this.setData(result.data);
    });
  },

  /**
   * 添加新地址
   */
  createAddress: function() {
    wx.navigateTo({
      url: './create'
    });
  },

  /**
   * 编辑地址
   */
  editAddress: function(e) {
    wx.navigateTo({
      url: "./detail?address_id=" + e.currentTarget.dataset.id
    });
  },

  /**
   * 移除收货地址
   */
  removeAddress: function(e) {
    let _this = this,
      address_id = e.currentTarget.dataset.id;
    wx.showModal({
      title: "提示",
      content: "您确定要移除当前收货地址吗?",
      success: function(o) {
        o.confirm && App._post_form('address/delete', {
          address_id
        }, function(result) {
          _this.getAddressList();
        });
      }
    });
  },
  add(e){
    console.log("ss",e);
    var _this = this;
    var personid = e.currentTarget.dataset.id;
    var token = wx.getStorageSync("token");
    if(!token){
      wx.navigateTo({
        url: '../login/login',
      });
      return;
    }
    console.log("personid",personid);
    App._post_form('wxapi/person/toupiao', {
      personid:personid,token:token
    }, function(result) {
        if(result.status=="200"){
          wx.showModal({
            title: '友情提示',
            content: "投票成功",
            showCancel: false,
            success(res) {
              _this.getdata("")
        
            }
          });
        }else{
          wx.showModal({
            title: '友情提示',
            content: result.message,
            showCancel: false,
            success(res) {
             
        
            }
          });
        }
    });

  },
  onShareAppMessage: function () {
   
  },

  //用户点击右上角分享朋友圈
  onShareTimeline: function () {
  
  },

});